﻿using System;
using System.Net;

namespace TcpSocketTaskDemo.Echo
{
    sealed class Tester : ITester
    {
        // *************************************************************** //
        #region [ member fields ]

        private readonly IPEndPoint m_svrEndpoint;

        #endregion

        // *************************************************************** //
        #region [ constructor ]

        public Tester(string ipaddress, int port)
        {
            m_svrEndpoint = Utility.CreateEndPoint(ipaddress, port);
        }

        #endregion

        // *************************************************************** //
        #region [ implement ITester ]

        public void RunAsServer()
        {
            using (Server server = new Server(m_svrEndpoint))
            {
                server.Start();
                Utility.WaitUserSignal();
            }// using
        }

        public void RunAsClient()
        {
            using (Client client = new Client(m_svrEndpoint))
            {
                client.Start(Utility.IntervalStrFactory(100, 100));
                Utility.WaitUserSignal();
            }// using
        }

        #endregion
    }
}
